/**
 * Created with IntelliJ IDEA.
 * User: suntao
 * Date: 16-9-28
 * Time: 下午12:38
 * To change this template use File | Settings | File Templates.
 */
$(function () {
	$("#normal_add").click(function() {
		normal_add("正常导入");
	});
	$("#exception_add").click(function() {
		exception_add("异常导入");
	});
    // 编辑广告 点击事件
    $(".a_ad_edit").click(function() {
        var ad_id =  $(this).parent().parent().children("td.ad_id").text();
        ad_edit("编辑广告", ad_id);
    });
    //查看详情
    $(".a_de_details").click(function() {
        var de_id =  $(this).parent().parent().children("td.de_id").text();
        de_details("翻译机详情", de_id);
    });
    // 点击删除
    $(".opt_del").click(function () {
        var $del = $(this);
        var de_id =  $(this).parent().parent().children("td.de_id").text();
        layer.confirm('确认要删除吗？', function (index) {
            de_del($del, de_id);
        });
    });

});
// 正常导入
function normal_add(title) {
    var index = layer.open({
        type: 2,
        title: title,
        content: "importPage.do"
    });
    layer.full(index);
}
//异常导入
function exception_add(title) {
    var index = layer.open({
        type: 2,
        title: title,
        content: "specialImportPage.do"
    });
    layer.full(index);
}
// 翻译机详情
function de_details(title, id) {
    var index = layer.open({
        type: 2,
        title: title,
        content: "getDeviceDetails.do?id=" + id
    });
    layer.full(index);
}

//翻译机-删除
function de_del(obj, id) {
    $.ajax({
        url: "deDelete.do",
        type: "post",
        async: true,
        data:"id=" + id,
        dataType: "json",
        success: function (data) {
            if (data["code"] == "1000") {
                location.replace(location.href);
//                $(obj).parents("tr").remove();
//                layer.msg('已删除!', {icon: 1, time: 1000});
            } else {
                layer.msg('删除失败!', {icon: 5, time: 1000});
            }
        },
        error: function (data) {
            layer.msg('操作失败!', {icon: 2, time: 1000});
        }
    });
}

function ad_batch_del(ids) {
    $.ajax({
        url: "adBatchDel.do",
        type: "post",
        async: true,
        data:"ids=" + ids,
        dataType: "json",
        success: function (data) {
            if (data["code"] == "1000") {
                location.replace(location.href);
//                $(obj).parents("tr").remove();
//                layer.msg('已删除!', {icon: 1, time: 1000});
            } else {
                layer.msg('删除失败!', {icon: 5, time: 1000});
            }
        },
        error: function (data) {
            layer.msg('操作失败!', {icon: 2, time: 1000});
        }
    });
}
